package YAPenvironment;

import java.awt.Color;
import java.awt.Image;
import java.net.URL;
import java.util.Random;

import javax.swing.ImageIcon;

/**
 * This Interface contains the constants, which are used for Server and Client
 * @author DMiagi
 *
 */

public abstract class YAPconstant {
	
	//Constants for both
	public static boolean C_DEBUG = false;
	public static final String C_MULTICASTGROUP="225.0.0.1";
	public static final int C_MAXPORT = 65536;
	public static final int C_MULTICASTPORT1=61152;
	public static final int C_MULTICASTPORT2=61153;
	public static final int C_UDP_SOCKET = C_MULTICASTPORT2+13;
	
	//Constants for the server
	public static final int C_MAXCONNECTIONS = 100;
	public static final int C_COUNTDOWNTIME=1000;
	public static final int C_MINPLAYERS = 2;
	public static final int C_MAXPLAYERS = 8;
	public static final int C_MINWALLS = 3;
	public static final int C_MAXWALLS = 12;
	public static final int C_MINNAMELENGTH = 4;
	public static final int C_MAXNAMELENGTH = 14;
	public static final int C_MINLIVES = 1;
	public static final int C_MAXLIVES = 10;
	public static final int C_GAMESIZE = 600; //To make it easier, a quadratic PlayingField
	public static final int FGLO_PLAYGROUNDSIZE = 400;
	
	public static final double C_BALLSTARTSPEED = 3; //speed in Pixel per 1/30s
	public static final double C_BALLRADIUS = 5;
	public static final int C_MODLIFE = 500; //number of ticks a mod stays active
	public static final int C_LIVES = 3;
	public static final double C_SLIDERSPEED = 6;
	public static final double C_SLIDERSIZE = 0.1;  //percentage of wall size
	public static final double C_MINSLIDERSIZE = 3; //can be changed later
	
	public static final String C_SEPARATOR = "\t";
	public static final String C_NEWLINE = "\b";
	public static final String C_CMD_SEPARATOR = ";";
	public static final String C_CHATWHISPERCMD = "/";
	
	//Constants for the Client

	public static final URL imgURL = YAPconstant.class.getResource( "logoYAP.png" );
	public static final Image ICONIMAGE= new ImageIcon(imgURL).getImage();
	public static URL manualURL = YAPconstant.class.getResource( "Manual.txt" );
	public static final int C_PORT=3141;
	public static final double C_FPS_LIMIT = 60;
	public static final int C_ALIVE_INTERVAL=1000;
	public static final long C_ALIVE_TIMEOUT = 5000;
	public static final int C_ENDINGTIME = 10000;
	
	//Constants for drawing stuff
	//Whole Playground
	public static final int C_LINETHICKNESS=10; // Walls and Sliders will be that fat, only use even numbers
	public static final Color C_BACKGROUND_COLOR = Color.BLACK;
	public static final Color C_WALL_COLOR = Color.WHITE;
	//Game-Mode
	public static final Color C_MOD_COLOR = Color.YELLOW;
	public static final Color C_GLOBALMOD_COLOR = Color.MAGENTA;
	public static final Color C_SLIDER_COLOR = Color.WHITE;
	public static final Color C_PONG_COLOR = Color.WHITE;
	public static final Color C_MODWALL_COLOR = Color.BLUE;
	public static final Color C_WINNER_COLOR = Color.GREEN;
	public static final Color C_LOSER_COLOR = Color.RED;
	public static final Color C_PAUSE_COLOR = Color.YELLOW;
	//Lobby-Mode
	public static final Color C_HOVER_COLOR = Color.BLUE;
	public static final Color C_ASSIGNED_COLOR = Color.RED;
	public static final Color C_OWNASSIGNED_COLOR = Color.GREEN;
	public static final Color C_STARTCOUNTER_COLOR = Color.RED;

	public static final String[] congrats={"WON THE GAME", "WAS THE BEST", "DEFEATED THE OTHERS", "IS UNSTOPPABLE", "PWND EVERYONE", "THE DESTROYER"};
	
	/**
	 * Returns a random Message to describe the winning player
	 * @return Winning Message
	 */
	public static String getCongratulations(){
		Random r = new Random();
		return congrats[r.nextInt(congrats.length)];
	}
	/**
	 * Sets whether or not to show the error trace or other debug messages in the console
	 * @param debug
	 */
	public static void setDebug(boolean debug){
		C_DEBUG = debug;
	}
	
	/**
	 * Enum to determine the Side State, used in sendPlayGround Command
	 */
	public static enum SideState {
		none(0), wall(1), modWall(2);
		
	    public static SideState getEnumByInt(int i){
	    	switch(i){
	    	case(0):
	    			return SideState.none;
	    	case(1): 
	    			return SideState.wall;
	    	case(2): 
	    			return SideState.modWall;
	    	}
			return SideState.none;
	    }

	    private final int value;
	    SideState(int idx) { 
			this.value = idx; 
		}
	    
	    public int getValue() { 
	    	return value; 
	    }	
	}

	/**
	 * Enum to determine the Mod State, used in sendPlayGround Command
	 */
	public static enum ModState {
		none (0), player(1), global(2);
		
		public static Color getColorByInt(int i){
	    	switch(i){
	    	case(0):
    				return C_MOD_COLOR;
	    	case(1):
	    			return C_MOD_COLOR;
	    	case(2): 
	    			return C_GLOBALMOD_COLOR;
	    	}
			return C_MOD_COLOR;
		}
		
	    public static ModState getEnumByInt(int i){
	    	switch(i){
	    	case(0):
    				return ModState.none;
	    	case(1):
	    			return ModState.player;
	    	case(2): 
	    			return ModState.global;
	    	}
			return ModState.none;
	    }

	    private final int value;
	    ModState(int idx) { 
			this.value = idx; 
		}
	    
	    public int getValue() { 
	    	return value; 
	    }	
	}
	
	
	
	/**
	 * The enum which contains all commands. Client and Server, TCP and UDP are communicating with these commands
	 */
	public static enum Command {
		 connect, disconnect, changeName, isAliveClient, isAliveServer, getHighScore, kick,
		 getLobbyList, getLobbyInformation, joinLobby, createLobby, //lobby related keywords
	     createPlayField, sendMsg, sendMsgTo, sendMsgFrom, setReady, setUnReady, leaveLobby, pickSide, startGame, getPlayerList,//in-lobby keywords
	     sendKey, noMove, pause, leaveGame, sendPlayGround, playerLostLife, sendPowerUpPos, sendSound, rotate, endGame,//in-game keywords
	     commandNotFound, 
	}
}
